//用户信息数据
function createUserList() {
  return [
    {
      userId: 1,
      avatar:
        'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
      username: 'admin',
      password: '111111',
      desc: '平台管理员',
      roles: ['平台管理员'],
      buttons: ['cuser.detail'],
      routes: ['home'],
      token: 'Admin Token',
    },
    {
      userId: 2,
      avatar:
        'https://ts1.cn.mm.bing.net/th/id/R-C.0015900115c31f78de7fb6590929f86a?rik=wsTFI5PMeJbUFw&riu=http%3a%2f%2fimg.touxiangwu.com%2fzb_users%2fupload%2f2022%2f10%2f202210101665362233123282.jpg&ehk=4kFt5oVBoLEIkY9L2Bsdz%2brWzqY7tzYTaDcM0yMjwXM%3d&risl=&pid=ImgRaw&r=',
      username: 'system',
      password: '111111',
      desc: '系统管理员',
      roles: ['系统管理员'],
      buttons: ['cuser.detail', 'cuser.user'],
      routes: ['home'],
      token: 'System Token',
    },
  ]
}

export default [
  // 用户登录接口
  {
    url: "/api/user/login",
    method: "post",
    response: ({ body }) => {
      const { username, password } = body;
      const checkUser = createUserList().find(item =>
        item.username === username && item.password === password
      );

      if (!checkUser) {
        return {
          code: 201,
          data: {
            message: "账号或密码错误"
          }
        }
      } else {
        // console.log("mock"+checkUser);
        
        const { token } = checkUser;
        return {
          code: 200, data: { token }
        }
      }
    }
  },
  // 获取用户信息
  {
    url: '/api/user/info',
    method: 'get',
    response: (request) => {
      //获取请求头携带token
      const token = request.headers.token;
      //查看用户信息是否包含有次token用户
      const checkUser = createUserList().find((item) => item.token === token)
      //没有返回失败的信息
      if (!checkUser) {
        return { code: 201, data: { message: '获取用户信息失败' } }
      }
      //如果有返回成功信息
      return { code: 200, data: { checkUser } }
    },
  },
]